package com.xms.configuration.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xms.configuration.entity.Usercustomization;
import com.xms.configuration.data.UsercustomizationMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author migo
 * @since 2021-11-13
 */
@Service
public class UserCustomizationService extends ServiceImpl<UsercustomizationMapper, Usercustomization> implements IUserCustomizationService {

    @Override
    public Usercustomization getByName(UUID ownerId, String name) {
        return super.getOne(new LambdaQueryWrapper<Usercustomization>()
                .eq(Usercustomization::getOwnerid, ownerId)
                .eq(Usercustomization::getName, name));
    }

    @Override
    public List<Usercustomization> getByNames(UUID ownerId, List<String> names) {
        return super.list(new LambdaQueryWrapper<Usercustomization>()
                .eq(Usercustomization::getOwnerid, ownerId)
                .in(Usercustomization::getName, names));
    }

    @Override
    public boolean saveMany(List<Usercustomization> entityList) {
        for (Usercustomization entity : entityList){
            this.save(entity);
        }
        return true;
    }

    @Override
    public boolean save(Usercustomization entity){
        //先删后加
        super.remove(new LambdaQueryWrapper<Usercustomization>()
                .eq(Usercustomization::getOwnerid, entity.getOwnerid())
                .eq(Usercustomization::getName, entity.getName()));
        return super.save(entity);
    }
}
